﻿Imports System.Data.OleDb

Public Class Register
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
    End Sub

    Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, False)

        Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
        If String.IsNullOrEmpty(continueUrl) Then
            continueUrl = "~/editProfile.aspx"
        End If


        '''Add the user to the profiles table
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("quizzes_db_ConnectionString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand("INSERT INTO profiles (UserName) VALUES (@UserName)", oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@UserName", RegisterUser.UserName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        Response.Redirect(continueUrl)
    End Sub
End Class